<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <%@ include file="/commons/script.jsp" %>
    <title>分配用户角色</title>
<body>
  <div class="m_right">
     <div class="m_r_tips">
     <div class="m_r_lefttips">您现在的位置：<a href="${ctx}/admin/home.jsp">首页</a>&gt;账号管理&gt;分配用户角色</div>
       <jsp:include page="/commons/admin/admin_login_remind.jsp"/>
    </div>

    <s:if test="hasActionMessages()">
          <div class="success">
               <s:actionmessage/>
          </div>
    </s:if>
     <s:if test="hasActionErrors()">
          <div class="error">
               <s:actionerror/>
          </div>
    </s:if>
    <s:form name="assgin_form" id="assgin_form" method="post" action="doAssginRole" namespace="/admin/account">
        <input type="hidden" value="${aid}" name="aid" />
        <input type="hidden" value="" name="origin_role_ids" id="origin_role_ids"/>
        <input type="hidden" value="" name="change_role_ids" id="change_role_ids"/>
    <div class="m_r_table">
       <table width="100%" border="0" cellspacing="1" cellpadding="0">
         <thead>
          <tr>
            <td class="m_r_table_td" colspan="8" >
                            账号${username} 可以分配的角色有：
            </td>
            </tr>
          <tr>
            <td class="m_r_table_tr bold"><input type="checkbox" value="" id = "p_box"/></td>
            <td class="m_r_table_tr bold">角色名称</td>
            <td class="m_r_table_tr bold">角色描述</td>
          </tr>
          </thead>
          <tbody>
              
          <!-- Map的key有rid、roleName、description、createTime、createUser、modifyTime、modifyUser -->
         <s:iterator value="#request.roleList" status="rowstatus" var="role">
               <tr>
                    <td><input type="checkbox" value="${role['rid'] }" name = "s_box"  ${not empty role.checked ? "checked = 'true'" : ""} /></td>
                    <td>${role['roleName']}</td>
                    <td>${role['description']}</td>
              </tr>
             </s:iterator>
          </tbody>
        </table>
    </div>
   
    <div class="m_r_search_btn">
      <s:submit value="添加" cssClass="text_btn" onclick="assgin_roles();return false;"/>
      <input type="button" value="返回" class="text_btn" onclick="history.go(-1);"/>
    </div>
    </s:form>
</div>

</body>
<script src="${ctx}/js/checkbox-table.js" type="text/javascript"></script>
<script type="text/javascript">
function assgin_roles() {
    var change_role_values = getCheckValues();
    if (getCheckCountByName('s_box') == 0){
      alert("请选择分配的角色！");
      return;
    }
    $("#origin_role_ids").val(getInitCheckValues());
    $("#change_role_ids").val(change_role_values);
    $("#assgin_form").submit();
}

$("#go_view").click(function(){
    var c = getCheckCount();
    if (c > 1) {
      alert("只能选择一个角色");
      return;
    } else if (c == 0){
      alert("请选择要分配的角色");
      return;
    }
    var single_box_value = getCheckValues();
    single_box_value = single_box_value.replace(/#/,"");
    window.location.href = "${ctx}/admin/role/viewRolePerm.do?rid=" + single_box_value;
});

var initCheckValue = "";
initCheckValue = getCheckValues();
function getInitCheckValues() {
	return initCheckValue;
}

</script>
</html>
